package ;

import flixel.FlxSprite;
import flixel.util.FlxPoint;

/**
 * ...
 * @author LF
 */
class ItemHolder extends FlxSprite
{
	
	private var _heldItem:Item;
	
	public function new(X:Float=0, Y:Float=0) 
	{
		super(X, Y);
		loadGraphic(AssetPaths.no_item__png);
	}
	
	public function setItem(item:Item):Void
	{
		if (_heldItem == null)
		{
			_heldItem = item;
			loadGraphicFromSprite(item);
			setGraphicSize(80, 80);
			updateHitbox();
			item.visible = false;
		}
	}
	
	public function getItem():Item
	{
		loadGraphic(AssetPaths.no_item__png);
		var screenPos:FlxPoint = getScreenXY();
		_heldItem.setPosition(screenPos.x, screenPos.y);
		_heldItem.visible = true;
		var tempItem = _heldItem;
		_heldItem = null;
		setGraphicSize(80, 80);
		updateHitbox();
		return tempItem;
	}
	
	public function heldItemName():String
	{
		return _heldItem.name;
	}
    
    public function heldItemScore():Int
    {
        return _heldItem.worth;
    }
	
	public function hasItem():Bool
	{
		return (_heldItem != null);
	}
	
	public function consumeItem():Void {
		loadGraphic(AssetPaths.no_item__png);
		setGraphicSize(80, 80);
		updateHitbox();
		_heldItem.kill();
		_heldItem = null;
	}
	
}